package base.display.activity;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.widget.BaseAdapter;
import android.widget.GridView;

/**
 * 抽象列表适配<br>
 */
public abstract class BaseGridAdapter extends BaseAdapter {
	/**
	 * My listview.
	 */
	protected GridView mGridView;

	/**
	 * My listview belonged context.
	 */
	private Context mContext;

	/**
	 * My listview belonged activity.
	 */
	private Activity mActivity;

	/**
	 * 列表数据对象<br>
	 */
	protected List<?> mList;

	/**
	 * 日志标识
	 */
	protected final String TAG = this.getClass().getSimpleName();

	/**
	 * 
	 * @param gridView
	 *            The listview
	 * @param dataList
	 *            The data list
	 */
	public BaseGridAdapter(GridView gridView, List<?> dataList) {
		mGridView = gridView;
		mList = dataList;
		mContext = gridView.getContext();
		mActivity = (Activity) mContext;
		mGridView.setAdapter(this);
	}

	protected Fragment mFragment;

	public BaseGridAdapter(Fragment fragment, GridView gridView, List<?> dataList) {
		this(gridView, dataList);
		mFragment = fragment;
	}

	public Fragment getFragment() {
		return mFragment;
	}

	/**
	 * Get the context.
	 * 
	 * @return
	 */
	public final Context getContext() {
		return mContext;
	}

	/**
	 * Get the activity.
	 * 
	 * @return
	 */
	public final Activity getActivity() {
		return mActivity;
	}

	/**
	 * Get the data list.
	 * 
	 * @return
	 */
	public List<?> getList() {
		return mList;
	}

	
	public int getCount() {
		return mList == null ? 0 : mList.size();
	}

	public Object getItem(int position) {
		return mList == null ? 0 : mList.get(position);
	}

	@SuppressWarnings("rawtypes")
	public void setList(List list) {
		mList = list;
	}

	public long getItemId(int position) {
		return position;
	}

}
